class Solution:
  def twoSum(self, nums, target):
    """
    :type nums: List[int]
    :type target: int
    :rtype: List[int]
    """
    dictDiff = {} # 用字典记录一个另一个加数与其序号的map，通过空间换取时间，只需要一次遍历
    for (i, val) in enumerate(nums):
      diff = target - val
      if diff in dictDiff:
        return [dictDiff[diff], i]
      
      dictDiff[val] = i

s = Solution()
print(s.twoSum([2, 7, 11, 15], 9))